<template>
  <div class="home-page">
    <!-- 轮播图 -->
    <div class="banner-section">
      <el-carousel 
        height="100vh" 
        indicator-position="outside"
        arrow="always"
        :interval="5000"
        trigger="hover"
      >
        <el-carousel-item v-for="(banner, index) in banners" :key="index">
          <div class="carousel-content">
            <el-image :src="banner.image" fit="cover" class="carousel-image" />
            <div class="carousel-overlay">
              <h2>{{ banner.title }}</h2>
              <p>{{ banner.desc }}</p>
              <el-button type="primary" size="large" @click="router.push(banner.path)">
                {{ banner.buttonText }}
              </el-button>
            </div>
          </div>
        </el-carousel-item>
      </el-carousel>
    </div>

    <!-- 数据统计 -->
    <div class="stats-section">
      <el-row :gutter="20">
        <el-col :span="6" v-for="stat in statistics" :key="stat.title">
          <div class="stat-card">
            <el-icon :size="40" :color="stat.color">
              <component :is="stat.icon" />
            </el-icon>
            <div class="stat-info">
              <div class="stat-value">{{ stat.value }}</div>
              <div class="stat-title">{{ stat.title }}</div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <!-- 特色功能区块 -->
    <div class="feature-section">
      <h2 class="section-title">特色功能</h2>
      <el-row :gutter="30">
        <el-col 
          v-for="(feature, index) in features" 
          :key="index" 
          :xs="24" :sm="12" :md="8"
        >
          <div class="feature-card" @click="handleFeatureClick(feature.path)">
            <div class="feature-icon">
              <el-icon :size="50" :color="feature.color">
                <component :is="feature.icon" />
              </el-icon>
            </div>
            <div class="feature-content">
              <h3>{{ feature.title }}</h3>
              <p>{{ feature.desc }}</p>
            </div>
            <div class="feature-arrow">
              <el-icon><ArrowRight /></el-icon>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>

    <!-- 非遗精选展示 -->
    <div class="heritage-showcase">
      <div class="showcase-header">
        <h2 class="section-title">非遗精选</h2>
        <el-tabs v-model="activeCategory" class="category-tabs">
          <el-tab-pane 
            v-for="category in categories" 
            :key="category.value" 
            :label="category.label" 
            :name="category.value"
          />
        </el-tabs>
      </div>
      
      <el-row :gutter="20">
        <el-col 
          v-for="item in filteredHeritage" 
          :key="item.id" 
          :xs="24" :sm="12" :md="8" :lg="6"
        >
          <div class="heritage-card" @click="router.push(`/heritage/${item.id}`)">
            <div class="heritage-image">
              <el-image 
                :src="item.cover" 
                fit="cover"
                :hide-on-click-modal="true"
                :preview-teleported="false"
                :preview-src-list="[]"
              >
                <template #error>
                  <div class="image-placeholder"></div>
                </template>
              </el-image>
              <div class="heritage-overlay">
                <el-tag :type="item.level === '国家级' ? 'danger' : 'warning'" size="small" class="level-tag">
                  {{ item.level }}
                </el-tag>
              </div>
            </div>
            <div class="heritage-info">
              <h3>{{ item.name }}</h3>
              <p>{{ item.description }}</p>
              <div class="heritage-meta">
                <el-tag size="small" effect="plain">{{ item.category }}</el-tag>
                <span class="region">{{ item.region }}</span>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>

      <div class="showcase-footer">
        <el-button 
          type="primary" 
          size="large"
          @click="router.push('/heritage/list')"
        >
          查看更多非遗项目
          <el-icon class="ml-2"><ArrowRight /></el-icon>
        </el-button>
      </div>
    </div>

    <!-- 最新动态 -->
    <div class="news-section">
      <h2 class="section-title">最新动态</h2>
      <el-row :gutter="20">
        <el-col :span="16">
          <div class="news-main">
            <div class="news-card" v-for="news in mainNews" :key="news.id" @click="handleNewsClick(news)">
              <el-image :src="news.image" fit="cover" class="news-image" />
              <div class="news-content">
                <h3>{{ news.title }}</h3>
                <p>{{ news.summary }}</p>
                <div class="news-meta">
                  <span>{{ news.date }}</span>
                  <el-tag size="small">{{ news.category }}</el-tag>
                </div>
              </div>
            </div>
          </div>
        </el-col>
        <el-col :span="8">
          <div class="news-sidebar">
            <h3 class="sidebar-title">热门活动</h3>
            <div class="event-list">
              <div class="event-item" v-for="event in upcomingEvents" :key="event.id">
                <div class="event-date">
                  <span class="day">{{ event.day }}</span>
                  <span class="month">{{ event.month }}</span>
                </div>
                <div class="event-info">
                  <h4>{{ event.title }}</h4>
                  <p>{{ event.location }}</p>
                </div>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>
    </div>
  </div>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue';
import { useRouter } from 'vue-router';
import { 
  Location, 
  Picture, 
  VideoCamera,
  Collection,
  User,
  Medal,
  Trophy,
  ArrowRight
} from '@element-plus/icons-vue';
import { useHeritageStore } from '../stores/heritageStore';
import HeritageCard from '@/components/HeritageCard.vue'

// Import banner images directly
const bannerImage1 = new URL('../assets/banners/image1.jpg', import.meta.url).href;
const bannerImage2 = new URL('../assets/banners/image2.jpg', import.meta.url).href;
const bannerImage3 = new URL('../assets/banners/image3.jpg', import.meta.url).href;

// Import news images
const newsImage1 = new URL('../assets/news/2024-01-15_heritage-symposium.jpg', import.meta.url).href;
const newsImage2 = new URL('../assets/news/2024-01-10_craft-revival-plan.jpg', import.meta.url).href;

const router = useRouter();
const heritageStore = useHeritageStore();

// 轮播图数据
const banners = ref([
  {
    image: bannerImage1,
    title: '守护非遗文化',
    desc: '传承千年技艺，弘扬中华文明',
    buttonText: '探索非遗',
    path: '/heritage/list'
  },
  {
    image: bannerImage2,
    title: '非遗地图',
    desc: '探索全国非遗分布',
    buttonText: '查看地图',
    path: '/heritage/map'
  },
  {
    image: bannerImage3,
    title: 'AR体验',
    desc: '科技赋能文化传承',
    buttonText: '开始体验',
    path: '/ar-experience'
  }
]);

// 数据统计
const statistics = ref([
  {
    icon: Collection,
    value: '1,234',
    title: '非遗项目',
    color: '#409EFF'
  },
  {
    icon: User,
    value: '567',
    title: '传承人',
    color: '#67C23A'
  },
  {
    icon: Medal,
    value: '89',
    title: '国家级项目',
    color: '#E6A23C'
  },
  {
    icon: Trophy,
    value: '456',
    title: '省级项目',
    color: '#F56C6C'
  }
]);

// 特色功能
const features = ref([
  {
    icon: Location,
    title: '非遗地图',
    desc: '探索全国非遗分布，了解各地特色文化',
    path: '/heritage/map',
    color: '#409EFF'
  },
  {
    icon: Picture,
    title: 'AR体验',
    desc: '通过AR技术，近距离感受非遗魅力',
    path: '/ar-experience',
    color: '#67C23A'
  },
  {
    icon: VideoCamera,
    title: '匠人直播',
    desc: '直击传统工艺现场，与传承人互动',
    path: '/live',
    color: '#E6A23C'
  }
]);

// 非遗分类
const categories = ref([
  { label: '全部', value: 'all' },
  { label: '传统技艺', value: '传统技艺' },
  { label: '传统美术', value: '传统美术' },
  { label: '传统音乐', value: '传统音乐' },
  { label: '传统舞蹈', value: '传统舞蹈' },
  { label: '传统戏剧', value: '传统戏剧' }
]);

const activeCategory = ref('all');

// 精选非遗项目
const featuredHeritage = ref([]);

// 最新动态
const mainNews = ref([
  {
    id: 1,
    title: '非遗保护与传承研讨会成功举办',
    summary: '来自全国各地的非遗传承人和专家学者齐聚一堂，共同探讨非遗保护与传承的新思路。',
    image: newsImage1,
    date: '2024-01-15',
    category: '新闻动态'
  },
  {
    id: 2,
    title: '传统工艺振兴计划启动',
    summary: '国家启动传统工艺振兴计划，助力非遗传承与发展。',
    image: newsImage2,
    date: '2024-01-10',
    category: '政策动态'
  }
]);

// 即将举行的活动
const upcomingEvents = ref([
  {
    id: 1,
    title: '非遗文化节',
    location: '北京国家博物馆',
    day: '20',
    month: '1月'
  },
  {
    id: 2,
    title: '传统工艺展',
    location: '上海文化中心',
    day: '25',
    month: '1月'
  },
  {
    id: 3,
    title: '非遗传承人培训',
    location: '广州文化馆',
    day: '30',
    month: '1月'
  }
]);

// 计算属性
const filteredHeritage = computed(() => {
  if (activeCategory.value === 'all') {
    return heritageStore.heritageList.slice(0, 6);
  }
  return heritageStore.heritageList.filter(item => item.category === activeCategory.value).slice(0, 6);
});

// 方法
const handleBannerClick = (banner) => {
  router.push(banner.path);
};

const handleFeatureClick = (path) => {
  router.push(path);
};

const handleNewsClick = (news) => {
  // 处理新闻点击
  console.log('News clicked:', news);
};

onMounted(() => {
  // 获取精选非遗项目
  featuredHeritage.value = heritageStore.heritageList.slice(0, 6);
});
</script>

<style scoped>
.home-page {
  @apply min-h-screen bg-gray-50;
}

/* 轮播图部分 */
.banner-section {
  width: 100%;
  height: 100vh;
  position: relative;
}

.carousel-content {
  position: relative;
  width: 100%;
  height: 100%;
}

.carousel-image {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.carousel-overlay {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: white;
  z-index: 2;
  width: 80%;
  max-width: 800px;
  background: rgba(0, 0, 0, 0.6);
  padding: 2rem;
  border-radius: 10px;
  backdrop-filter: blur(5px);
}

.carousel-overlay h2 {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  font-weight: 700;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.carousel-overlay p {
  font-size: 1.2rem;
  margin-bottom: 2rem;
  text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.5);
}

.carousel-overlay .el-button {
  padding: 0.8rem 2rem;
  font-size: 1.1rem;
  border-radius: 30px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.3s ease;
  background: linear-gradient(45deg, #4CAF50, #45a049);
  border: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.carousel-overlay .el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #45a049, #4CAF50);
}

:deep(.el-carousel__container) {
  height: 100vh;
}

:deep(.el-carousel__item) {
  height: 100vh;
}

:deep(.el-carousel__indicators) {
  bottom: 20px;
}

:deep(.el-carousel__arrow) {
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  width: 40px;
  height: 40px;
}

:deep(.el-carousel__arrow:hover) {
  background-color: rgba(0, 0, 0, 0.7);
}

/* 数据统计部分 */
.stats-section {
  margin-bottom: 40px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.el-row {
  margin-bottom: 20px;
}

.el-col {
  padding: 0 10px;
}

.stat-card {
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  text-align: center;
}

.el-icon {
  font-size: 40px;
  color: #409EFF;
  margin-bottom: 10px;
}

.stat-info {
  text-align: center;
}

.stat-value {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.stat-title {
  font-size: 1rem;
  color: #606266;
}

/* 特色功能区块 */
.feature-section {
  margin-bottom: 40px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}

.section-title {
  font-size: 2rem;
  font-weight: 700;
  margin-bottom: 20px;
  text-align: center;
}

.el-row {
  margin-bottom: 30px;
}

.el-col {
  padding: 0 10px;
}

.feature-card {
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  text-align: center;
  cursor: pointer;
}

.feature-icon {
  font-size: 50px;
  color: #409EFF;
  margin-bottom: 10px;
}

.feature-content {
  text-align: center;
}

.feature-arrow {
  font-size: 1.5rem;
  color: #409EFF;
  margin-top: 10px;
}

/* 非遗精选展示 */
.heritage-showcase {
  @apply py-12 px-4;
}

.showcase-header {
  @apply mb-8;
}

.section-title {
  @apply text-3xl font-bold text-center mb-8;
}

.heritage-card {
  @apply bg-white rounded-lg overflow-hidden shadow-md mb-6 cursor-pointer
         transition-transform duration-300 hover:transform hover:scale-105;
}

.heritage-image {
  @apply relative h-48;
}

.heritage-image :deep(.el-image) {
  @apply w-full h-full;
}

.heritage-image :deep(.el-image img) {
  @apply object-cover;
}

.heritage-overlay {
  @apply absolute top-4 right-4;
}

.level-tag {
  @apply text-sm font-medium;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.heritage-info {
  @apply p-4;
}

.heritage-info h3 {
  @apply text-lg font-bold mb-2 text-gray-900;
}

.heritage-info p {
  @apply text-sm text-gray-600 mb-4 line-clamp-2;
}

.heritage-meta {
  @apply flex items-center justify-between;
}

.region {
  @apply text-sm text-gray-500;
}

.showcase-footer {
  @apply mt-12 text-center;
}

.el-button {
  padding: 0.8rem 2rem;
  font-size: 1.1rem;
  border-radius: 30px;
  text-transform: uppercase;
  letter-spacing: 1px;
  transition: all 0.3s ease;
  background: linear-gradient(45deg, #4CAF50, #45a049);
  border: none;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.el-button:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  background: linear-gradient(45deg, #45a049, #4CAF50);
}

/* 最新动态 */
.news-section {
  @apply py-12 bg-gray-50;
}

.news-main {
  padding: 20px;
  background-color: white;
}

.news-card {
  background-color: white;
  padding: 20px;
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
  cursor: pointer;
  margin-bottom: 20px;
}

.news-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 20px;
}

.news-content {
  text-align: center;
}

.news-content h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 5px;
}

.news-content p {
  font-size: 1rem;
  color: #606266;
}

.news-meta {
  margin-top: 10px;
}

.news-sidebar {
  padding: 20px;
  background-color: white;
}

.sidebar-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.event-list {
  margin-bottom: 20px;
}

.event-item {
  margin-bottom: 10px;
}

.event-date {
  font-size: 1rem;
  font-weight: 700;
  margin-right: 10px;
}

.event-info {
  font-size: 1rem;
  color: #606266;
}

.image-placeholder {
  @apply w-full h-full bg-gray-100;
}
</style>